	<CFQUERY NAME = "getBROWSEFIELDS" datasource="#CLIENT.GLOBAL_DSN#">
		SELECT TABLENAME,COLUMNNAME,COLUMNTYPE,COLUMNDESC,FIELDGROUP,DEFAULTVALUE,COLUMNREQUIRED
		FROM GRGBOSETABLEFIELDS
		WHERE TABLENAME = <cfqueryparam value="#THETABLE#" cfsqltype="cf_sql_varchar">
			AND ISVISIBLEEFORM = 'Y'
		ORDER BY COLUMNORDER
	</CFQUERY>
	<CFQUERY NAME = "getDATEFIELD" datasource="#CLIENT.COMPANY_DSN#" maxrows="1">
		SELECT DATEFIELD
		FROM ECRGDTRDTL
		WHERE EDTRCODE = <cfqueryparam value="#sEDTRCODE#" cfsqltype="cf_sql_varchar"> AND FORMCODE_FK IN
			(SELECT FORMCODE FROM ECRGFORMS WHERE TABLENAME_FK = <cfqueryparam value="#THETABLE#" cfsqltype="cf_sql_varchar">)
	</CFQUERY>
	<cfquery name="getpreprocess" datasource="#client.company_dsn#">
		select preprocess
		from ecrgforms
		where formcode = <cfqueryparam value="#theformcode#" cfsqltype="cf_sql_varchar">
	</cfquery>
	<cfset thepreprocess = getpreprocess.preprocess>
<CFSET insertfields = "PERSONNELIDNO,">
<CFSET insertvals = "'#PID#',">
<cfset dateinside = false>
<CFLOOP QUERY = "GETBROWSEFIELDS">
	<CFSET insertfields = INSERTFIELDS &"#COLUMNNAME#">
	<CFIF CURRENTROW NEQ RECORDCOUNT>
		<CFSET insertfields = INSERTFIELDS &",">
	</CFIF>
	<cfif columntype neq "ftdatetime">
		<CFSET INSERTVALS = INSERTVALS &"'" &"#EVALUATE("FORM.EDT#COLUMNNAME#")#" &"'">
	<cfelse>
		<CFSET INSERTVALS = INSERTVALS &"#EVALUATE("FORM.EDT#COLUMNNAME#")#">
	</cfif>
	<CFIF CURRENTROW NEQ RECORDCOUNT>
		<CFSET INSERTVALS = INSERTVALS &",">
	</CFIF>
	<cfif listfindnocase(valuelist(getdatefield.datefield),columnname)>
		<cfif EVALUATE("FORM.EDT#COLUMNNAME#") gte dCutOffstart and EVALUATE("FORM.EDT#COLUMNNAME#") lte dCutOffend>
			<cfset dateinside = true>
		</cfif>
	</cfif>
</CFLOOP>
<CFOUTPUT>
<cfif dateinside>
	<CFIF STRUCTKEYEXISTS(FORM,"hidEDIT")>
		<cftry>
		<!---<CFQUERY name="del#THETABLE#" datasource="#CLIENT.COMPANY_DSN#">
			DELETE FROM #THETABLE#
			WHERE DOCNUMBER = '#FORM.hidEDIT#'
				AND PERSONNELIDNO = '#PID#'
		</CFQUERY>
		<CFQUERY name="insert#THETABLE#" datasource="#CLIENT.COMPANY_DSN#">
			INSERT INTO #THETABLE# (#INSERTFIELDS#)
			VALUES (#PRESERVESINGLEQUOTES(INSERTVALS)#)
		</CFQUERY>--->
		<cfquery name="updaterec" datasource="#client.company_dsn#" >
			update #thetable#
			set
				<cfloop query="getbrowsefields">
					<cfif columntype neq "ftdatetime">
						#columnname# = <cfqueryparam value="#EVALUATE("FORM.EDT#COLUMNNAME#")#" cfsqltype="cf_sql_varchar">,
					<cfelse>
						#columnname# = <cfqueryparam value="#EVALUATE("FORM.EDT#COLUMNNAME#")#" cfsqltype="cf_sql_timestamp">,
					</cfif>
				</cfloop>
				datelastupdate = <cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">,
				timelastupdate =  <cfqueryparam value="#timeformat("#now()#","HH:MM:SS")#" cfsqltype="cf_sql_varchar">,
				userid = <cfqueryparam value="#client.userid#" cfsqltype="cf_sql_varchar">
		</cfquery>	
		<!---<CFQUERY name="updateORIG<!---#DN#--->" datasource="#CLIENT.COMPANY_DSN#">
			UPDATE #THETABLE#
			SET ROUTEID = '#THETABLE##FORM.EDTDOCNUMBER#'
			WHERE DOCNUMBER = '#FORM.EDTDOCNUMBER#'
		</CFQUERY>--->
		<cfset session.themessage = "Record was successfully saved.">
		<cfcatch>
							<cfif cfcatch.Type eq "database">
					<cfquery name="geterrormessage" datasource="#client.global_dsn#">
						select message
						from grgbosemessages
						where componentcode = 'DB'
							and messagecode = '#cfcatch.NativeErrorCode#'
					</cfquery>
					<cfset session.themessage = "Application was not saved.<br>" &geterrormessage.message>	
				<cfelse>
					<cfset session.themessage = "Application was not saved.<br>" &cfcatch.message &"<br>" &cfcatch.detail>
				</cfif>
		</cfcatch>
		</cftry>
	<cfelse>
		<cfif thepreprocess eq "">
			<cftry>
			<CFQUERY name="insert" datasource="#CLIENT.COMPANY_DSN#">
				INSERT INTO #THETABLE# (#INSERTFIELDS#)
				VALUES (#PRESERVESINGLEQUOTES(INSERTVALS)#)
			</CFQUERY>
			<cfquery name="insertupdatedtl" datasource="#client.company_dsn#">
				INSERT INTO ECINDTRUPDATEDTL(PID,DOCNUMBER,FORMCODE_FK,DOCNUMBER_FK,ROUTEID,RECCREATEDBY,RECDATECREATED)
				VALUES ('#PID#','#THEDOCNUMBER#','#THEFORMCODE#','#FORM.EDTDOCNUMBER#','#THETABLE##FORM.EDTDOCNUMBER#','#CLIENT.USERID#',#NOW()#)
			</cfquery>
			<CFQUERY name="updateORIG" datasource="#CLIENT.COMPANY_DSN#">
				UPDATE #THETABLE#
				SET ROUTEID = '#THETABLE##FORM.EDTDOCNUMBER#'
				WHERE DOCNUMBER = '#FORM.EDTDOCNUMBER#'
			</CFQUERY>	
			<cfset session.themessage = "Application was saved successfully and was automatically included in this eDTR upon routing.">
			<cfcatch>
				<cfif cfcatch.Type eq "database">
					<cfquery name="geterrormessage" datasource="#client.global_dsn#">
						select message
						from grgbosemessages
						where componentcode = 'DB'
							and messagecode = '#cfcatch.NativeErrorCode#'
					</cfquery>
					<cfset session.themessage = "Application was not saved.<br>" &geterrormessage.message>	
				<cfelse>
					<cfset session.themessage = "Application was not saved.<br>" &cfcatch.message &"<br>" &cfcatch.detail>
				</cfif>
			</cfcatch>
			</cftry>
		<cfelse>
			<!---validate preprocess--->
			<cfinclude template="./func_validatepreprocess.cfm">
			<cfif lpreprocessvalidated>
				<cftry>
				<CFQUERY name="insert#THETABLE#" datasource="#CLIENT.COMPANY_DSN#">
					INSERT INTO #THETABLE# (#INSERTFIELDS#)
					VALUES (#PRESERVESINGLEQUOTES(INSERTVALS)#)
				</CFQUERY>
				<cfquery name="insertupdatedtl" datasource="#client.company_dsn#">
					INSERT INTO ECINDTRUPDATEDTL(PID,DOCNUMBER,FORMCODE_FK,DOCNUMBER_FK,ROUTEID,RECCREATEDBY,RECDATECREATED)
					VALUES ('#PID#','#THEDOCNUMBER#','#THEFORMCODE#','#FORM.EDTDOCNUMBER#','#THETABLE##FORM.EDTDOCNUMBER#','#CLIENT.USERID#',#NOW()#)
				</cfquery>
				<CFQUERY name="updateORIG" datasource="#CLIENT.COMPANY_DSN#">
					UPDATE #THETABLE#
					SET ROUTEID = '#THETABLE##FORM.EDTDOCNUMBER#'
					WHERE DOCNUMBER = '#FORM.EDTDOCNUMBER#'
				</CFQUERY>
				<cfset session.themessage = "Application was saved successfully and was automatically included in this eDTR upon routing.">
				<cfcatch>
									<cfif cfcatch.Type eq "database">
					<cfquery name="geterrormessage" datasource="#client.global_dsn#">
						select message
						from grgbosemessages
						where componentcode = 'DB'
							and messagecode = '#cfcatch.NativeErrorCode#'
					</cfquery>
					<cfset session.themessage = "Application was not saved.<br>" &geterrormessage.message>	
				<cfelse>
					<cfset session.themessage = "Application was not saved.<br>" &cfcatch.message &"<br>" &cfcatch.detail>
				</cfif>
				</cfcatch>
				</cftry>
			<cfelse>
				<cfset session.themessage = "Application was not saved. <BR>" &sedtrmess>
			</cfif>
		</cfif>
	</CFIF>	
<cfelse>
	<!---<script language="javascript" type="text/javascript">
		alert('Cannot save an application beyond the cut-off');
	</script>--->
	<cfset session.themessage = "Cannot save an application beyond the cut-off.">
</cfif>
</CFOUTPUT>
